﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using webui.Models;
using webui.ViewModel;

namespace webui.Areas.Admin.Controllers
{
    public class AdminController : Controller
    {

        [HttpGet]
        [Skip]
        public ActionResult Login()
        {

            return View();
        }


        [HttpPost]
        [Skip]
        public ActionResult Login(v_LoginUser userinfo)
        {

            if (!ModelState.IsValid)
            {
                return OperateContext.Current.RedirectAjax("err", "没有权限!", null, "");
            }

            if (OperateContext.Current.LoginAdmin(userinfo))
            {

                return OperateContext.Current.RedirectAjax("ok", "登陆成功~", null, "/admin/admin/index");
            }
            else
            {
                return OperateContext.Current.RedirectAjax("err", "用户名或密码错误~~!", null, "");
            }

        }


        [SkipPemission]
        public ActionResult Index()
        {
            ViewBag.username = OperateContext.Current.Usr.username;
            return View();
        }

        [Skip]
        public ActionResult Quit()
        {
            Session["ainfo"] = null;
            Session.Clear();
            HttpCookie myCookie = Request.Cookies["ainfo"];
            if (myCookie != null)
            {
                myCookie.Path = "/admin/";
                myCookie.Expires = DateTime.Today.AddDays(-1);
                Response.Cookies.Add(myCookie);
            }

            return Redirect("login");

        }


       
        //  根据当前登陆用户 权限  生成菜单 
        [AjaxRequest]
        [SkipPemission]
        public ActionResult GetMenuData()
        {
            return Content(OperateContext.Current.UsrTreeJsonStr);
        }


    }
}